package 力扣;

/**
 示例 1:
 输入:       1         1
 / \       / \
 2   3     2   3
 [1,2,3],   [1,2,3]
 输出: true
 示例 2:
 输入:      1          1
 /           \
 2             2
 [1,2],     [1,null,2]
 输出: false
 示例 3:
 输入:       1         1
 / \       / \
 2   1     1   2
 [1,2,1],   [1,1,2]

 输出: false
 */
public class _100相同的树 {

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if( p==null && q ==null ) return true;
        if( p ==null || q== null ) return false;
        if( p.val != q.val) return false;
        return  isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }
}
